pull: Support --mirror option
authorColin Walters <walters@verbum.org>
Mon, 16 Jun 2014 21:11:50 +0000 (17:11 -0400)
committerColin Walters <walters@verbum.org>
Mon, 16 Jun 2014 21:14:13 +0000 (17:14 -0400)
There's several use cases for calling into ostree itself to do
mirroring, instead of using bare rsync.  For example, it's a bit more
efficient as it doesn't require syncing the objects/ directory.

https://bugzilla.gnome.org/show_bug.cgi?id=728351

src/libostree/ostree-repo-pull.c
src/libostree/ostree-repo.h
src/ostree/ot-builtin-pull.c
tests/pull-test.sh

index 467d27e962c504a5fd397200000149754ea8bfdd..dbcdc4050534c01a74e971bd76dcb8d4843e338f 100644 (file)
@@ -1262,8 +1262,8 @@ ostree_repo_pull (OstreeRepo               *self,
         }
       else
         {
-          ostree_repo_transaction_set_ref (pull_data->repo, pull_data->remote_name, ref, checksum);
-
+          gboolean is_mirror = (pull_data->flags & OSTREE_REPO_PULL_FLAGS_MIRROR) > 0;
+          ostree_repo_transaction_set_ref (pull_data->repo, is_mirror ? NULL : pull_data->remote_name, ref, checksum);
         }
     }
 
index 562e6c1867a6e671472242fab38e2289849bd18b..ccd9f4076f2dbfa62a887fc97697c379d72a5c1c 100644 (file)
@@ -510,9 +510,11 @@ gboolean ostree_repo_prune (OstreeRepo        *self,
 /**
  * OstreeRepoPullFlags:
  * @OSTREE_REPO_PULL_FLAGS_NONE: No special options for pull
+ * @OSTREE_REPO_PULL_FLAGS_MIRROR: Write out refs suitable for mirrors
  */
 typedef enum {
-  OSTREE_REPO_PULL_FLAGS_NONE
+  OSTREE_REPO_PULL_FLAGS_NONE,
+  OSTREE_REPO_PULL_FLAGS_MIRROR
 } OstreeRepoPullFlags;
 
 gboolean ostree_repo_pull (OstreeRepo             *self,
index 4ed1a151fb580a7b38d7d005672eab784c533d12..1cf3bb78c39f337750d101cb8f2a9ea1d45105ba 100644 (file)
 #include "otutil.h"
 
 static gboolean opt_disable_fsync;
+static gboolean opt_mirror;
 
 static GOptionEntry options[] = {
   { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL },
+  { "mirror", 0, 0, G_OPTION_ARG_NONE, &opt_mirror, "Write refs suitable for a mirror", NULL },
   { NULL }
 };
 
@@ -60,6 +62,9 @@ ostree_builtin_pull (int argc, char **argv, OstreeRepo *repo, GCancellable *canc
   if (opt_disable_fsync)
     ostree_repo_set_disable_fsync (repo, TRUE);
 
+  if (opt_mirror)
+    pullflags |= OSTREE_REPO_PULL_FLAGS_MIRROR;
+
   if (strchr (argv[1], ':') == NULL)
     {
       remote = g_strdup (argv[1]);
index 8231cefd0542c23cdb5c57246d47572b89de12e5..dc92e97f1167bec0a4aeb4a21a5e2ad732aff44b 100755 (executable)
@@ -36,6 +36,15 @@ assert_file_has_content firstfile '^first$'
 assert_file_has_content baz/cow '^moo$'
 echo "ok pull contents"
 
+cd ${test_tmpdir}
+mkdir mirrorrepo
+ostree --repo=mirrorrepo init --mode=archive-z2
+${CMD_PREFIX} ostree --repo=mirrorrepo remote add --set=gpg-verify=false origin $(cat httpd-address)/ostree/gnomerepo
+${CMD_PREFIX} ostree --repo=mirrorrepo pull --mirror origin main
+${CMD_PREFIX} ostree --repo=mirrorrepo fsck
+$OSTREE show main >/dev/null
+echo "ok pull mirror"
+
 cd ${test_tmpdir}
 ostree --repo=ostree-srv/gnomerepo commit -b main -s "Metadata string" --add-detached-metadata-string=SIGNATURE=HANCOCK --tree=ref=main
 ${CMD_PREFIX} ostree --repo=repo pull origin main